<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" href="../../../css/allApp.css" />
		<link href="../../../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/css.css" />
		<style type="text/css">
		.textarea textarea{
			min-height: 100px;
		}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">免巡检申请</h1>
		</header>
		<div class="mui-content">
			<div class="xj-content">
				<div class="H-10"></div>
				<div class="mui-card">
					<!--页眉，放置标题-->
					<!--内容区-->
					<div class="mui-card-content" style="border: 0;">
						<p class="biaozhun"></p>
						<div class="yichang-text">
							<div class="textarea">

								<textarea placeholder="请输入"></textarea>
							</div>
						</div>

					</div>
				</div>
			</div>
		</div>
		<div class="btn">
			<button type="button" class="mui-btn mui-btn-primary mui-col-2 " id="sure">确定</button>
			<button type="button" class="mui-btn mui-btn-default mui-col-2" id="cancle">取消</button>
		</div>
		<script src="../../../js/mui.min.js"></script>
		<script src="../../../js/jquery-3.2.1.min.js"></script>
		<script type="text/javascript" src="../../../js/mkeyplus.base.xunjian.js"></script>
		<script src="../../../js/uuid.js"></script>
		<script type="text/javascript" src="../../../js/common.js"></script>
		<script src="./../js/mui.previewimage.js"></script>
		<script src="./../js/mui.zoom.js"></script>
		<script type="text/javascript">
			mui.init()
			mui.previewImage();
			//添加图片
			var pid = '';
			mui.plusReady(function() {
				var self = plus.webview.currentWebview();
				var Idarr= self.Idarr;
				var xjtype= self.xjtype;
				pid = self.xsdwindid;
				Idarr=Idarr.join(',');
				console.log('userid',localStorage.getItem('userid'));
				mui('.btn').on('tap', '#sure', function() {
					var Text = $('.textarea textarea').val().trim();
					var main = plus.webview.getWebviewById("xianchangxunjian.html");
					if(Text==""){
						mui.toast('请填写原因');
					}else{
						var btnArr = ['确认', '取消'];
						mui.confirm('确认提交吗?', '操作提示', btnArr, function(e) {
							if(e.index == 0) {
								console.log('Idarr');
								plus.nativeUI.showWaiting('提交中...');
								mui.baseApp.httpRequst('/api/v2/sbxj/UpdateNotXjList', {
									xjIds: Idarr,
									reason: Text,
									memberId: localStorage.getItem('userid')
								}, function(data) {
									plus.nativeUI.closeWaiting();
									console.log('111111' + JSON.stringify(data));
									if(data.status == "200") {
										mui.toast(data.message);
										
										if(xjtype == 'pinci'){
											updatePcChild(self.Idarr);
										}else if(xjtype == 'xianlu'){
											updateXlChild(self.Idarr);
										}
										
										plus.webview.currentWebview().close();
										// var id=plus.webview.currentWebview().opener().id;
										if(xjtype == 'shebei'){
											var id=plus.webview.currentWebview().opener().id;
											var page1 = plus.webview.getWebviewById('dxjchild/sb_sub.html');
											mui.fire(page1, 'refresh2');
										}else{
											var page1 = plus.webview.getWebviewById('weixunjianlist.html');
											mui.fire(page1, 'refresh');
										}
										
										var page = plus.webview.getWebviewById("jiankong.html");
										mui.fire(page, 'home');
									} else if(data.status == "400") {
										mui.toast(data.message);
									}

								})
							}

						});
					}
					
				});
				mui('.btn').on('tap', '#cancle', function() {
					mui.back();
				});
				
			});
			
			function updatePcChild(arrid){
				var pcchild = plus.storage.getItem('pcchild') || '[]';
				pcchild = JSON.parse(pcchild);
				for (var i = 0; i < pcchild.length; i++) {
					if(pcchild[i].key == pid){
						var arr = pcchild[i].value;
						for (var k = 0; k < arrid.length; k++) {
							for (var j = 0; j < arr.length; j++) {
								if(arr[j].id == arrid[k]){
									arr[j].status = 5;
									arr[j].flags = 'one';
									pcchild[i].value = arr;
								}
							}
						}
					}
				}
				plus.storage.setItem('pcchild',JSON.stringify(pcchild));
			}
			
			function updateXlChild(arrid){
				var xlchild = plus.storage.getItem('xlchild') || '[]';
				xlchild = JSON.parse(xlchild);
				for (var i = 0; i < xlchild.length; i++) {
					if(xlchild[i].key == pid){
						var arr = xlchild[i].value;
						for (var k = 0; k < arrid.length; k++) {
							for (var j = 0; j < arr.length; j++) {
								if(arr[j].id == arrid[k]){
									arr[j].status = 5;
									arr[j].flags = 'one';
									xlchild[i].value = arr;
								}
							}
						}
					}
				}
				plus.storage.setItem('xlchild',JSON.stringify(xlchild));
			}
		</script>
	</body>

</html>